Mark the thread from the worker pool.#152
Merged
ioquatix merged 2 commits intosocketry:mainfrom Nov 16, 2025
Merged
Conversation
If we don't mark them, the thread object can be freed as soon as it ends.
It doesn't seem to be a problem when the worker pool just has 1 thread,
but if there are multiple threads then each call to `Thread#join` can
cause a GC step as it calls back into ruby.
If you do this:
```
class ::Thread
alias_method :old_join, :join
def join(timeout=nil)
4.times { GC.start }
old_join(timeout)
end
end
```
and set the size pool to be > 1, it can crash.
ioquatix
approved these changes
Nov 15, 2025
Member
ioquatix
left a comment
There was a problem hiding this comment.
LGTM, thanks for this excellent fix.
ef2d35b to
44666dc
Compare
nateberkopec
added a commit
to nateberkopec/io-event
that referenced
this pull request
Nov 16, 2025
Commit 903522e contained git diff syntax that was accidentally committed to the source file. This commit: - Removes the errant git diff line (@@ -214,7 +227,7 @@) - Restores proper tab indentation throughout create_worker_thread - Ensures all worker struct fields are properly initialized The functionality from PR socketry#152 (marking threads for GC) is preserved. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If we don't mark them, the thread object can be freed as soon as it ends. It doesn't seem to be a problem when the worker pool just has 1 thread, but if there are multiple threads then each call to
Thread#joincan cause a GC step as it calls back into ruby.If you do this you'll get a pretty consistent crash: